define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {



            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'subject/index' + location.search,
                    add_url: 'subject/add',
                    edit_url: 'subject/edit',
                    del_url: 'subject/del',
                    multi_url: 'subject/multi',
                    table: 'subject',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                onLoadSuccess:function(){
                    // 这里就是数据渲染结束后的回调函数
                    $(".btn-editone").data("area", ['95%', '95%']);//编辑

                },

                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'subject_cate_id', title: __('Sublect_cate_id'),searchList: Config.subject_cate_list,operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'category_id', title: __('Category_id'),searchList: Config.subjectcategorylist,operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        // {field: 'guidance', title: __('Guidance'), operate: false,width:'200px', class: 'autocontent',formatter:Table.api.formatter.content },
                        // {field: 'desc', title: __('Desc'),  operate: false,width:'200px', class: 'autocontent',formatter:Table.api.formatter.content},
                        {field: 'content', title: __('Content'), operate: 'LIKE'},
                        {field: 'time', title: __('Time'), operate: 'LIKE'},
                        {field: 'source', title: __('Source'), operate: 'LIKE'},
                        {field: 'require', title: __('Require'), operate: 'LIKE'},
                        // {field: 'personnel_tags', title: __('Personnel_tags'), operate: 'LIKE'},
                        {field: 'updatetime', title: __('Updatetime'),operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'weigh', title: __('Weigh'),operate:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [

                                {
                                    name: 'timu',
                                    classname: 'btn btn-xs   btn-dialog btn-reject',
                                    url: 'subject_exam/index?subject_id={id}',
                                    text: '题目管理',
                                    extend: 'data-toggle="tooltip"  data-area=["100%","100%"]',
                                    visible: function (row) {
                                        return true;
                                    },
                                    title: function (row) {
                                        return '题目管理' + '-' + row.name;
                                    },
                                },
                                {
                                    name: 'result',
                                    classname: 'btn btn-xs   btn-dialog btn-reject',
                                    url: 'subject_result/index?subject_id={id}',
                                    text: '设置结果',
                                    extend: 'data-toggle="tooltip"  data-area=["100%","100%"]',
                                    visible: function (row) {
                                        // 判断当前行数据中的 status 字段的值是否等于 1
                                        return true;
                                    },
                                    title: function (row) {
                                        return '设置结果' + '-' + row.name;
                                    },
                                }
                            ]
                        }
                    ]
                ]
            });
         $(".search input").attr('placeholder','请输入测评题库');
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
